package com.sunday.scoremanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.scoremanager.R;
import com.sunday.scoremanager.entity.StaffAccount;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.sunday.scoremanager.base.Constants.TEST_URL;

/**
 * Created by 刘涛 on 2017/10/27.
 */

public class StaffAccountAdapter extends RecyclerView.Adapter {


    private Context mContext;
    private List<StaffAccount> dataSet;
    private LayoutInflater layoutInflater;
    private View.OnClickListener onClickListener;

    public StaffAccountAdapter(Context context, List<StaffAccount> datas) {
        this.mContext = context;
        this.dataSet = datas;
        this.layoutInflater = LayoutInflater.from(mContext);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.list_staff_account_item, null);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ListHolder listHolder = (ListHolder) holder;
        StaffAccount item=dataSet.get(position);

        listHolder.accountName.setText("账号:"+item.getUserName());

        listHolder.btnEdit.setTag(item);
        listHolder.btnDelete.setTag(item);

        listHolder.btnDelete.setOnClickListener(onClickListener);
        listHolder.btnEdit.setOnClickListener(onClickListener);

    }

    @Override
    public int getItemCount() {
        return dataSet.size();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    class ListHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.account_name)
        TextView accountName;
        @Bind(R.id.btn_delete)
        TextView btnDelete;
        @Bind(R.id.btn_edit)
        TextView btnEdit;


        public ListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
